import Vue from "vue";
import Vuex from "./kvuex";
// Vuex是一个插件，内部要提供install方法
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    counter: 1
  },
  mutations: {
    add(state) {
      state.counter++
    }
  },
  actions: {
    add({ commit }) {

      setTimeout(() => {
        console.log('this', this)
        commit('add')
      }, 1000)
    }
  },
  getters: {
    doubleCounter: (state) => {
      return state.counter * 2
    },
    thirdCounter: (state) => {
      return state.counter * 3
    }
  }
});
